<?
    require_once("dbconnect.php");
    require_once("admin_functions.php");
    require_once("classes/mail.php");
    //alter table `ep`.`customer` change `customer_id` `customer_id` int (11)  NOT NULL AUTO_INCREMENT , add primary key(`customer_id` )

    chk_session();

    if($_GET['action'] == "DELETE") {
        $query_data = "Delete from scrap where scrap_id=".$_REQUEST['scrap_id'];
        $result_update	= mysql_query ( $query_data ) or die(mysql_error());
        $message ='<div class="update_message">Scrap id:'.$_REQUEST['scrap_id'].' is deleted.</div>';
    }

    $sql1 = "select scrap.*, customer.name from customer, scrap where scrap.from = customer.customer_id 
        ORDER BY scrap_id DESC";

    $rs1 = mysql_query($sql1) or die(mysql_error());
    $cnt1 = mysql_num_rows($rs1);
?>

<?php require_once('include/header1.php'); ?>
<?php require_once('include/sidebar.php'); ?>
<div id="admin_full_inner_body" style="float:left;width:84%">
    <div id="page_heading">Manage Customer </div>
<?php
    if(!empty ($message)){
        echo $message;
    }
    ?>
    <table cellpadding="0" cellspacing="0" border="0" class="display" id="example" width="100%">
        <thead>
            <tr>
                <th>From Message (ID, Customer Name)</th>
                <th>To Message</th>
                <th>Message</th>
                <th>Message Date</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <?php while($row1=mysql_fetch_array($rs1)) { ?>
            <tr class="odd gradeX">
                <td><?php echo $row1['from']; ?>
                        <?php
                            if(!empty($row1['name'])) {
                                echo $row1['name'];
                            } else {
                                echo 'Customer is deleted.';
                            }
                        ?>
                </td>
                <th><?php echo $row1['to']; ?></th>
                <td class="center"> <?php echo $row1['scrap']; ?></td>
                <td class="center"><?= $row1['created_at']; ?></td>
                <th>
                    <a href="JavaScript:if(confirm('Are you sure you want to Delete this Scrap?')){self.location.href='check_messages.php?scrap_id=<?php echo $row1['scrap_id']; ?>&action=DELETE';}"
                       class="link-normal">Delete</a>
                </th>
            </tr>
                <?php } //end while ?>

        </tbody>
        <tfoot>
            <tr>
                <th>From Message (ID, Customer Name)</th>
                <th>To Message</th>
                <th>Message</th>
                <th>Message Date</th>
                <th>Action</th>
            </tr>
        </tfoot>
    </table>
</div>

<!-- middle_container ends -->
<?php require_once('include/footer1.php'); ?>
